package com.fengpanlong.util;

import java.util.List;


public class Pager<T> {
	private int totalCount;
	private int pageSize = 5;
	private int nowPageNum;
	private List<T> result;
	
	public Pager(int totalCount, int nowPageNum) {
		setTotalCount(totalCount);
		setNowPageNum(nowPageNum);
	}
	public int getTotalCount() {
		return totalCount;
	}
	private void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getPageSize() {
		return pageSize;
	}
	public int getNowPageNum() {
		return nowPageNum;
	}
	private void setNowPageNum(int nowPageNum) {
		if(nowPageNum < 1) {
			nowPageNum = 1;
		} else if(nowPageNum > getTotalPages()){
			nowPageNum = getTotalPages();
		}
		this.nowPageNum = nowPageNum;
	}
	public List<T> getResult() {
		return result;
	}
	public void setResult(List<T> result) {
		this.result = result;
	}
	public int getTotalPages(){
		int result = getTotalCount()/getPageSize();
		if(getTotalCount()%getPageSize() != 0 ){
			result++;
		}
		return result;
	}
	public int getStartIndex() {
		int index = (getNowPageNum() - 1) * getPageSize();
		return index;
	}
}
